package com.lfy.yunpicture.controller;

import com.lfy.yunpicture.common.BaseResponse;
import com.lfy.yunpicture.common.ErrorCode;
import com.lfy.yunpicture.common.ResultUtils;
import com.lfy.yunpicture.exception.ThrowUtils;
import com.lfy.yunpicture.model.dto.statistics.*;
import com.lfy.yunpicture.model.entity.User;
import com.lfy.yunpicture.model.vo.statistic.*;
import com.lfy.yunpicture.service.SpaceStatisticService;
import com.lfy.yunpicture.service.UserService;
import com.lfy.yunpicture.service.impl.SpaceStatisticServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 空间统计
 */
@RestController
@RequestMapping("/space_statistic")
@Slf4j
public class SpaceStatisticController {
    @Resource
    private UserService userService;
    @Resource
    private SpaceStatisticService spaceStatisticService;
    /**
     * 查询空间大小使用情况
     * @param spaceSizeUsageRequest
     * @param request
     */
    @PostMapping("/size")
    public BaseResponse<SpaceSizeUsageResponse> getSpaceSizeUsageSituation(@RequestBody SpaceSizeUsageRequest spaceSizeUsageRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spaceSizeUsageRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        SpaceSizeUsageResponse spaceSizeUsageSituation = spaceStatisticService.getSpaceSizeUsageSituation(spaceSizeUsageRequest, loginUser);
        return ResultUtils.success(spaceSizeUsageSituation);
    }
    /**
     * 查询空间分类使用情况
     * @param spaceCategoryUsageRequest
     * @param request
     */
    @PostMapping("/category")
    public BaseResponse<List<SpaceCategoryUsageResponse>> getSpaceCategoryUsageSituation(@RequestBody SpaceCategoryUsageRequest spaceCategoryUsageRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spaceCategoryUsageRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        List<SpaceCategoryUsageResponse> spaceCategoryUsageSituation = spaceStatisticService.getSpaceCategoryUsageSituation(spaceCategoryUsageRequest, loginUser);
        return ResultUtils.success(spaceCategoryUsageSituation);
    }
    /**
     * 查询空间标签使用情况
     */
    @PostMapping("/tag")
    public BaseResponse<List<SpaceTagUsageResponse>> getSpaceTagUsageSituation(@RequestBody SpaceTagUsageRequest spaceTagUsageRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spaceTagUsageRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        List<SpaceTagUsageResponse> spaceTagUsageSituation = spaceStatisticService.getSpaceTagUsageSituation(spaceTagUsageRequest, loginUser);
        return ResultUtils.success(spaceTagUsageSituation);
    }
    /**
     * 查询空间图片大小范围使用情况
     */
    @PostMapping("/picture/size")
    public BaseResponse<List<SpacePictureSizeRangeResponse>> getSpacePictureSizeRangeSituation(@RequestBody SpacePictureSizeRangeRequest spacePictureSizeRangeRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spacePictureSizeRangeRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        List<SpacePictureSizeRangeResponse> spacePictureSizeRangeSituation = spaceStatisticService.getSpacePictureSizeRangeSituation(spacePictureSizeRangeRequest, loginUser);
        return ResultUtils.success(spacePictureSizeRangeSituation);
    }
    /**
     * 查询空间图片上传日期情况
     */
    @PostMapping("/picture/upload")
    public BaseResponse<List<SpacePictureUploadConditionResponse>> getSpacePictureUploadConditionSituation(@RequestBody SpacePictureUploadConditionRequest spacePictureUploadConditionRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spacePictureUploadConditionRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        List<SpacePictureUploadConditionResponse> spacePictureUploadConditionSituation = spaceStatisticService.getSpacePictureUploadConditionSituation(spacePictureUploadConditionRequest,loginUser);
        return ResultUtils.success(spacePictureUploadConditionSituation);
    }
    /**
     * 查询空间排行榜
     */
    @PostMapping("/rank")
    public BaseResponse<List<SpaceUsageRankResponse>> getSpaceUsageRankSituation(@RequestBody SpaceUsageRankRequest spaceUsageRankRequest, HttpServletRequest request){
        // 校验参数
        ThrowUtils.throwIf(spaceUsageRankRequest == null, ErrorCode.PARAMS_ERROR);
        // 校验登录态
        User loginUser = userService.getLoginUser(request);
        List<SpaceUsageRankResponse> spaceUsageRankSituation = spaceStatisticService.getSpaceUsageRankSituation(spaceUsageRankRequest, loginUser);
        return ResultUtils.success(spaceUsageRankSituation);
    }
}
